package me.softwareengineer.guice.rendering.domain;

import java.util.Map;

import me.softwareengineer.guice.rendering.listener.Listener;
import me.softwareengineer.guice.rendering.listener.OnMacroEvent;

/**
 * Represents an macro in a page
 * 
 * @author yad.tahir
 * 
 *         <pre>
 * This class is thread-safe and can be cached/re-used and used concurrently.
 * </pre>
 */
public class MacroElement extends Element {
	/**
	 * Holds the id of macro. For instance, php for php macro
	 */
	private final String id;
	/**
	 * The macro content that we are preserving.
	 */
	private final String content;
	/**
	 * The macro is located in a inline content (like paragraph, etc.).
	 */
	private boolean isInline;
	
	/**
	 * Creates a macro element
	 * 
	 * @param id
	 *            the id of the macro. See {@link #getId()}
	 * @param isInline
	 *            If true the macro is located in a inline content (like
	 *            paragraph, etc.).
	 * @param properties
	 *            the properties of the element. See {@link HasProperties}
	 */
	public MacroElement(String id, boolean isInline,
			Map<String, String> properties) {
		super(properties);
		this.id = id;
		this.content = null;
		this.isInline = isInline;
	}

	/**
	 * Creates a macro element
	 * 
	 * @param id
	 *            the id of the macro. See {@link #getId()}
	 * @param isInline
	 *            If true the macro is located in a inline content (like
	 *            paragraph, etc.).
	 * @param content
	 *            the content/script of the macro. See {@link #getContent()}
	 * @param properties
	 *            the properties of the element. See {@link HasProperties}
	 */
	public MacroElement(String id, boolean isInline,
			Map<String, String> properties, String content) {
		super(properties);
		this.id = id;
		this.content = content;
		this.isInline = isInline;
	}

	/**
	 * 
	 * @return the content or the script of the macro
	 * <p>
	 * This property is immutable and thread-safe
	 * </p>
	 */
	public String getContent() {
		
			return content;
	}

	/**
	 * 
	 * @return the id of macro. For instance, php for php macro
	 * <p>
	 * This property is immutable and thread-safe
	 * </p>
	 */
	public String getId() {
		
			return id;
	}

	/**
	 * 
	 * @return if true the macro is located in a inline content (like paragraph,
	 *         etc.).
	 * <p>
	 * This property is immutable and thread-safe
	 * </p>        
	 */
	public boolean isInline() {
	
			return isInline;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void render(Listener listener) {
		OnMacroEvent event = new OnMacroEvent(getId(), isInline(),
				getContent(), getAllProperties());
		listener.onEvent(event);
	}

	
}
